package com.hnkywl.sts.action.zjgl;

import com.hnkywl.sts.entity.zjgl.Xjyh;
import com.hnkywl.sts.service.zjgl.XjyhService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 说明：
 * 包:        com.hnkywl.sts.action.zjgl
 * 类描述:    现金优惠Action类
 * 修改备注: [说明本次修改内容]
 * 版本:        [v1.0]
 */
@Namespace("/zjgl/xjyh")
public class XjyhAction extends SimpleActionSupport {
    private XjyhService xjyhService;
    //合同编号
    private String htbm;
    //id
    private Long xjyhId;
    //实体类实例化
    private Xjyh xjyh;
    private int page;
    //分页组件 页面大小
    private int rows = 10;

    @Action("xjyhList")
    public void xjyhList() {
        this.renderJson(this.xjyhService.findAllXjyh(htbm, page, rows));
    }

    @Action("xjyh_content")
    public String xjyh_content() {
        //进入update页面
        if (xjyhId != null) {
            xjyh = xjyhService.findXjyhDetail(xjyhId);
        } else {
            xjyh = new Xjyh();
        }
        return SUCCESS;
    }

    /**
     * 增加
     */
    @Action("add_xjyh")
    public void addxjyh() {
        try {
            this.xjyhService.addXjyh(xjyh);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 修改
     */
    @Action("update_xjyh")
    public void updateXjyh() {
        try {
            this.xjyhService.updateXjyh(xjyh, xjyhId);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 删除
     */
    @Action("del_xjyh")
    public void del_xjyh() {
        try {
            this.xjyhService.delXjyh(xjyhId);
            renderText("{\"statusCode\":\"200\",\"message\":\"删除成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    @Action("findXsjeByHtid")
    public void findXsjeByHtid() {
        this.renderJson(this.xjyhService.findXsjeByHtid(xjyhId));
    }

    @Autowired
    public void setXjyhService(XjyhService xjyhService) {
        this.xjyhService = xjyhService;
    }

    public String getHtbm() {
        return htbm;
    }

    public void setHtbm(String htbm) {
        this.htbm = htbm;
    }

    public Long getXjyhId() {
        return xjyhId;
    }

    public void setXjyhId(Long xjyhId) {
        this.xjyhId = xjyhId;
    }

    public Xjyh getXjyh() {
        return xjyh;
    }

    public void setXjyh(Xjyh xjyh) {
        this.xjyh = xjyh;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }
}
